package com.jacobson.core.di.components

import android.app.Application
import android.content.Context
import com.google.gson.Gson
import com.jacobson.core.base.delegate.AppDelegate
import com.jacobson.core.di.modules.AppModule
import com.jacobson.core.di.modules.ClientModule
import com.jacobson.core.di.modules.GlobalConfigurationModule
import com.jacobson.core.framework.dialog.DialogHandler
import com.jacobson.core.framework.errorhandler.RxErrorHandler
import com.jacobson.core.framework.repository.IRepositoryManager
import dagger.BindsInstance
import dagger.Component
import javax.inject.Named
import javax.inject.Singleton

/**
 * Dagger2 全局组件
 * @datetime 2018/7/16 8:51
 * @author Wucz
 */
@Singleton
@Component(modules = [
    GlobalConfigurationModule::class,
    AppModule::class,
    ClientModule::class
])
interface AppComponent {
    /*可以向外部提供[Application]类型实例*/
    fun application(): Application

    /**
     * 可以向外部提供[Context]类型
     */
    @Named("applicationContext")
    fun applicationContext(): Context

    /*可以向外部提供Gson*/
    fun gson(): Gson

    /*用于管理网络请求层,以及数据缓存层*/
    fun repositoryManager(): IRepositoryManager

    //RxJava 错误处理管理类
    fun rxErrorHandler(): RxErrorHandler

    //dialog处理
    fun dialogHandler(): DialogHandler

    fun inject(delegate: AppDelegate)

    @Component.Builder
    interface Builder {
        @BindsInstance
        fun application(application: Application): Builder

        fun globalConfigurationModule(globalConfigurationModule: GlobalConfigurationModule): Builder

        fun build(): AppComponent
    }
}